package com.infore.qualityControl.controller;

import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.infore.qualityControl.util.DateUtil;
import com.infore.qualityControl.util.ScaleUtil;
import com.infore.qualityControl.util.UUIDGenerator;

import io.swagger.annotations.ApiOperation;

@Controller
public class ImitateDataController {
    
    @Autowired
    DataSource DataSource;
    
    Connection connection = null;
    PreparedStatement pstmt = null;
    
    public static final List<String> indexCodeList = new ArrayList<String>(Arrays.asList("w01019","w21003","w21011","w21001"
            ,"w01001","w01010","w01009","w01014","w01003"));
    
    public static final List<String> checkCodeListOne = new ArrayList<String>(Arrays.asList("w01019","w21003","w21011","w21001"));
    
    public static final List<String> checkCodeListTwo = new ArrayList<String>(Arrays.asList("w01001","w01010","w01009","w01014","w01003"));
    
    @ApiOperation(value = "自动与手动模拟数据接口")
    @RequestMapping(value = "/automatic", method = RequestMethod.GET )
    @ResponseBody
    public void automaticData() {
        try {
            connection = DataSource.getConnection();
            // 编写Sql
            String sql = "INSERT INTO AUTOMATIC_MANUAL_COMPARISON (ID,STATION_CODE,TIME,INDEX_CODE,INDEX_NAME,INDEX_UNIT,SAMPLING_TIME,"
                    + "ARTIFICIAL_VALUE,AUTOMATIC_VALUE,ERROR_RATE,TECHNICAL_REQUIREMENT,QUALIFICATION) "
                    + "VALUES (?,?,TO_DATE(?,'yyyy-MM-dd HH24:mi:ss'),?,?,?,TO_DATE(?,'yyyy-MM-dd HH24:mi:ss'),?,?,?,?,?) ";
            pstmt = connection.prepareStatement(sql);
            for (int i = 1; i <= 60; i++) {
                int x = 0;
                String stationCode = "W" + i;
                for (int j = 1; j <= 74; j++) {
                    String time = "2020-01-18 9:00:00";
                    Date date = DateUtil.stringToDate(time, DateUtil.DATE_FULL_STR);
                    String hour = DateUtil.addDate(date, j, DateUtil.DATE_FULL_STR); 
                    String samHour = DateUtil.addMin(DateUtil.stringToDate(hour, DateUtil.DATE_FULL_STR), 23, DateUtil.DATE_FULL_STR);
                    for (String string : checkCodeListTwo) {
                        x++;
                        String artificialValue = "";
                        String automaticValue = "";
                        String indexName = "";
                        String indexUnit = "";
                        String technicalRequirement = "";
                        String errorRate = "";
                        String qualification = "";
                        if ("w01001".equals(string)) {
                            artificialValue = String.valueOf(new BigDecimal(10 + (Math.random() * 8))
                                    .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                            automaticValue = String.valueOf(new BigDecimal(10 + (Math.random() * 8))
                                    .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                            indexName = "PH";
                            indexUnit = "无量纲";
                            technicalRequirement = "≤±0.10pH";
                            Double error = Double.valueOf(ScaleUtil.sciCalSix(Double.valueOf(automaticValue) - Double.valueOf(artificialValue), 3));
                            if (error <= 0.1 && error >= -0.1) {
                                qualification = "合格";
                            } else {
                                qualification = "不合格";
                            }
                            errorRate = String.valueOf(error);
                        } else if ("w01010".equals(string)) {
                            artificialValue = String.valueOf(new BigDecimal(20 + (Math.random() * 5))
                                    .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                            automaticValue = String.valueOf(new BigDecimal(20 + (Math.random() * 5))
                                    .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                            indexName = "水温";
                            indexUnit = "℃";
                            technicalRequirement = "≤±0.5%";
                            Double error = Double.valueOf(ScaleUtil.sciCalSix(Double.valueOf(automaticValue) - Double.valueOf(artificialValue), 3));
                            if (error <= 0.5 && error >= -0.5) {
                                qualification = "合格";
                            } else {
                                qualification = "不合格";
                            }
                            errorRate = String.valueOf(error);
                        } else if ("w01009".equals(string)) {
                            artificialValue = String.valueOf(new BigDecimal(10 + (Math.random() * 5))
                                    .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                            automaticValue = String.valueOf(new BigDecimal(10 + (Math.random() * 5))
                                    .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                            indexName = "溶解氧";
                            indexUnit = "mg/L";
                            technicalRequirement = "≤±10%";
                            Double error = Double.valueOf(ScaleUtil.sciCalSix(Double.valueOf(automaticValue) - Double.valueOf(artificialValue), 3));
                            if (error <= 10 && error >= -10) {
                                qualification = "合格";
                            } else {
                                qualification = "不合格";
                            }
                            errorRate = String.valueOf(error);
                        } else if ("w01014".equals(string)) {
                            artificialValue = String.valueOf(new BigDecimal(10 + (Math.random() * 8))
                                    .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                            automaticValue = String.valueOf(new BigDecimal(10 + (Math.random() * 8))
                                    .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                            indexName = "电导率";
                            indexUnit = "μS/cm";
                            technicalRequirement = "≤±5%";
                            Double error = Double.valueOf(ScaleUtil.sciCalSix(Double.valueOf(automaticValue) - Double.valueOf(artificialValue), 3));
                            if (error <= 5 && error >= -5) {
                                qualification = "合格";
                            } else {
                                qualification = "不合格";
                            }
                            errorRate = String.valueOf(error);
                        } else if ("w01003".equals(string)) {
                            artificialValue = String.valueOf(new BigDecimal(10 + (Math.random() * 10))
                                    .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                            automaticValue = String.valueOf(new BigDecimal(10 + (Math.random() * 10))
                                    .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                            indexName = "浊度";
                            indexUnit = "NTU";
                            technicalRequirement = "≤±10%";
                            Double error = Double.valueOf(ScaleUtil.sciCalSix(Double.valueOf(automaticValue) - Double.valueOf(artificialValue), 3));
                            if (error <= 10 && error >= -10) {
                                qualification = "合格";
                            } else {
                                qualification = "不合格";
                            }
                            errorRate = String.valueOf(error);
                        }
                        String uuid = UUIDGenerator.getUUID();
                        // 判断是否存在
                        pstmt.setString(1, uuid);
                        pstmt.setString(2, stationCode);
                        pstmt.setString(3, hour);
                        pstmt.setString(4, string);
                        pstmt.setString(5, indexName);
                        pstmt.setString(6, indexUnit);
                        pstmt.setString(7, samHour);
                        pstmt.setString(8, artificialValue);
                        pstmt.setString(9, automaticValue);
                        pstmt.setString(10, errorRate);
                        pstmt.setString(11, technicalRequirement);
                        pstmt.setString(12, qualification);
                        pstmt.addBatch();
                        x++;
                        if (x % 20 == 0) {
                            pstmt.executeBatch();
                        }
                    }
                    pstmt.executeBatch();
                }
                System.out.println(stationCode + "站点插入" + x + "条数据！");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                if (connection != null) {
                    connection.close();
                }
                if (pstmt != null) {
                    pstmt.close();
                }
            } catch (SQLException e) {
                    e.printStackTrace();
            }
        }
    }
    
    @ApiOperation(value = "多点线性模拟数据接口")
    @RequestMapping(value = "/multipoint", method = RequestMethod.GET )
    @ResponseBody
    public void multipointData() {
        try {
            connection = DataSource.getConnection();
            // 编写Sql
            String sql = "INSERT INTO MULTIPOINT_LINEARITY (ID,STATION_CODE,BASIN_CODE,BASIN_NAME,AREA_CODE,AREA_NAME,OPERATION_NAME,TIME,"
                    + "INDEX_CODE,INDEX_NAME,INDEX_UNIT,FIRST_POINT_VALUE,SECOND_POINT_VALUE,THIRD_POINT_VALUE,FOURTH_POINT_VALUE,FIFTH_POINT_VALUE,"
                    + "SIXTH_POINT_VALUE,RELATED_COEFFICIENT) "
                    + "VALUES (?,?,?,?,?,?,?,TO_DATE(?,'yyyy-MM-dd HH24:mi:ss'),?,?,?,?,?,?,?,?,?,?) ";
            pstmt = connection.prepareStatement(sql);
            for (int i = 1; i <= 60; i++) {
                int x = 0;
                String stationCode = "W" + i;
                for (int j = 1; j <= 74; j++) {
                    String time = "2020-01-18 7:00:00";
                    Date date = DateUtil.stringToDate(time, DateUtil.DATE_FULL_STR);
                    String hour = DateUtil.addDate(date, j, DateUtil.DATE_FULL_STR); 
                    for (String string : checkCodeListOne) {
                        x++;
                        String firstValue = "";
                        String secondValue = "";
                        String threeValue = "";
                        String fourValue = "";
                        String fiveValue = "";
                        String sixValue = "";
                        String indexName = "";
                        String indexUnit = "";
                        if ("w01019".equals(string)) { // 5-10
                            firstValue = String.valueOf(new BigDecimal( 5 + (Math.random() * 10))
                                    .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                            secondValue = String.valueOf(new BigDecimal( 5 + (Math.random() * 10))
                                    .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                            threeValue = String.valueOf(new BigDecimal( 5 + (Math.random() * 10))
                                    .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                            fourValue = String.valueOf(new BigDecimal( 5 + (Math.random() * 10))
                                    .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                            fiveValue = String.valueOf(new BigDecimal( 5 + (Math.random() * 10))
                                    .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                            sixValue = String.valueOf(new BigDecimal( 5 + (Math.random() * 10))
                                    .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                            indexName = "高锰酸盐指数";
                            indexUnit = "mg/L";
                        } else if ("w21003".equals(string)) { // 0.7-0.9
                            firstValue = String.valueOf(new BigDecimal(0.7 + (Math.random() * 0.9))
                                    .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                            secondValue = String.valueOf(new BigDecimal(0.7 + (Math.random() * 0.9))
                                    .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                            threeValue = String.valueOf(new BigDecimal(0.7 + (Math.random() * 0.9))
                                    .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                            fourValue = String.valueOf(new BigDecimal(0.7 + (Math.random() * 0.9))
                                    .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                            fiveValue = String.valueOf(new BigDecimal(0.7 + (Math.random() * 0.9))
                                    .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                            sixValue = String.valueOf(new BigDecimal(0.7 + (Math.random() * 0.9))
                                    .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                            indexName = "氨氮";
                            indexUnit = "mg/L";
                        } else if ("w21011".equals(string)) { // 0.001-0.003
                            firstValue = String.valueOf(new BigDecimal(0.1 + (Math.random() * 0.3))
                                    .setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue());
                            secondValue = String.valueOf(new BigDecimal(0.1 + (Math.random() * 0.3))
                                    .setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue());
                            threeValue = String.valueOf(new BigDecimal(0.1 + (Math.random() * 0.3))
                                    .setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue());
                            fourValue = String.valueOf(new BigDecimal(0.1 + (Math.random() * 0.3))
                                    .setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue());
                            fiveValue = String.valueOf(new BigDecimal(0.1 + (Math.random() * 0.3))
                                    .setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue());
                            sixValue = String.valueOf(new BigDecimal(0.1 + (Math.random() * 0.3))
                                    .setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue());
                            indexName = "总磷";
                            indexUnit = "mg/L";
                        } else if ("w21001".equals(string)) { // 0.01-0.1
                            firstValue = String.valueOf(new BigDecimal(3 + (Math.random() * 5))
                                    .setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue());
                            secondValue = String.valueOf(new BigDecimal(3 + (Math.random() * 5))
                                    .setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue());
                            threeValue = String.valueOf(new BigDecimal(3 + (Math.random() * 5))
                                    .setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue());
                            fourValue = String.valueOf(new BigDecimal(3 + (Math.random() * 5))
                                    .setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue());
                            fiveValue = String.valueOf(new BigDecimal(3 + (Math.random() * 5))
                                    .setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue());
                            sixValue = String.valueOf(new BigDecimal(3 + (Math.random() * 5))
                                    .setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue());
                            indexName = "总氮";
                            indexUnit = "mg/L";
                        }
                        String uuid = UUIDGenerator.getUUID();
                        // 判断是否存在
                        pstmt.setString(1, uuid);
                        pstmt.setString(2, stationCode);
                        pstmt.setString(3, "XA_WATER");
                        pstmt.setString(4, "白洋淀");
                        pstmt.setString(5, "130632");
                        pstmt.setString(6, "安新县");
                        pstmt.setString(7, "宇星科技发展(深圳)有限公司");
                        pstmt.setString(8, hour);
                        pstmt.setString(9, string);
                        pstmt.setString(10, indexName);
                        pstmt.setString(11, indexUnit);
                        pstmt.setString(12, firstValue);
                        pstmt.setString(13, secondValue);
                        pstmt.setString(14, threeValue);
                        pstmt.setString(15, fourValue);
                        pstmt.setString(16, fiveValue);
                        pstmt.setString(17, sixValue);
                        pstmt.setString(18, indexUnit);
                        pstmt.addBatch();
                        x++;
                        if (x % 20 == 0) {
                            pstmt.executeBatch();
                        }
                    }
                    pstmt.executeBatch();
                }
                System.out.println(stationCode + "站点插入" + x + "条数据！");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                if (connection != null) {
                    connection.close();
                }
                if (pstmt != null) {
                    pstmt.close();
                }
            } catch (SQLException e) {
                    e.printStackTrace();
            }
        }
    }
    
    @ApiOperation(value = "加标回收率模拟数据接口")
    @RequestMapping(value = "/recoveryData", method = RequestMethod.GET )
    @ResponseBody
    public void recoveryData() {
        try {
            connection = DataSource.getConnection();
            // 编写Sql
            String sql = "INSERT INTO RECOVERY_DATA (RECOVERY_ID,DATA_TIME,FACTOR_CODE,FLAG,MN,WATER_TIME,WATER,CHECK_DATA,CHROMA_VALUE,VOLUME,DVOLUME) "
                    + "VALUES (?,TO_DATE(?,'yyyy-MM-dd HH24:mi:ss'),?,?,?,TO_DATE(?,'yyyy-MM-dd HH24:mi:ss'),?,?,?,?,?) ";
            pstmt = connection.prepareStatement(sql);
            for (int i = 1; i <= 60; i++) {
                int x = 0;
                String stationCode = "W" + i;
                for (int j = 1; j <= 74; j++) {
                    String time = "2020-01-18 10:00:00";
                    Date date = DateUtil.stringToDate(time, DateUtil.DATE_FULL_STR);
                    String hour = DateUtil.addDate(date, j, DateUtil.DATE_FULL_STR); 
                    String waterTime = DateUtil.addHour(hour, 1, DateUtil.DATE_FULL_STR);
                    for (String string : checkCodeListOne) {
                        x++;
                        String value = "";
                        String water = "";
                        String chromaValue = "";
                        String volume = "";
                        String dvolume = "";
                        if ("w01019".equals(string)) { // 5-10
                            value = String.valueOf(new BigDecimal( 5 + (Math.random() * 15))
                                    .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                            water = String.valueOf(new BigDecimal( 2 + (Math.random() * 10))
                                    .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                            volume = String.valueOf(new BigDecimal((Math.random() * 1))
                                    .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                            chromaValue = "200";
                            dvolume = "40";
                        } else if ("w21003".equals(string)) { // 0.7-0.9
                            value = String.valueOf(new BigDecimal(1 + (Math.random() * 3))
                                    .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                            water = String.valueOf(new BigDecimal( 0.5 + (Math.random() * 2))
                                    .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                            volume = String.valueOf(new BigDecimal((Math.random() * 1))
                                    .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                            chromaValue = "400";
                            dvolume = "196";
                        } else if ("w21011".equals(string)) { // 0.001-0.003
                            value = String.valueOf(new BigDecimal(0.1 + (Math.random() * 0.5))
                                    .setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue());
                            water = String.valueOf(new BigDecimal( 0.1 + (Math.random() * 0.2))
                                    .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                            volume = String.valueOf(new BigDecimal( 1 + (Math.random() * 1.5))
                                    .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                            chromaValue = "50";
                            dvolume = "190";
                        } else if ("w21001".equals(string)) { // 0.01-0.1
                            value = String.valueOf(new BigDecimal(9 + (Math.random() * 9.5))
                                    .setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue());
                            water = String.valueOf(new BigDecimal( 6 + (Math.random() * 7))
                                    .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                            volume = String.valueOf(new BigDecimal(1 + (Math.random() * 1.5))
                                    .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                            chromaValue = "500";
                            dvolume = "190";
                        } else if ("w01001".equals(string)) {
                            value = String.valueOf(new BigDecimal(7 + (Math.random() * 1))
                                    .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                        } else if ("w01010".equals(string)) {
                            value = String.valueOf(new BigDecimal(20 + (Math.random() * 5))
                                    .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                        } else if ("w01009".equals(string)) {
                            value = String.valueOf(new BigDecimal(5 + (Math.random() * 2))
                                    .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                        } else if ("w01014".equals(string)) {
                            value = String.valueOf(new BigDecimal(400 + (Math.random() * 20))
                                    .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                        } else if ("w01003".equals(string)) {
                            value = String.valueOf(new BigDecimal(20 + (Math.random() * 15))
                                    .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                        }
                        String uuid = UUIDGenerator.getUUID();
                        // 判断是否存在
                        pstmt.setString(1, uuid);
                        pstmt.setString(2, waterTime);
                        pstmt.setString(3, string);
                        pstmt.setString(4, "N");
                        pstmt.setString(5, stationCode);
                        pstmt.setString(6, hour);
                        pstmt.setString(7, water);
                        pstmt.setString(8, value);
                        pstmt.setString(9, chromaValue);
                        pstmt.setString(10, volume);
                        pstmt.setString(11, dvolume);
                        pstmt.addBatch();
                        x++;
                        if (x % 20 == 0) {
                            pstmt.executeBatch();
                        }
                    }
                    pstmt.executeBatch();
                }
                System.out.println(stationCode + "站点插入" + x + "条数据！");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                if (connection != null) {
                    connection.close();
                }
                if (pstmt != null) {
                    pstmt.close();
                }
            } catch (SQLException e) {
                    e.printStackTrace();
            }
        }
    }
    
    @ApiOperation(value = "核查模拟数据接口")
    @RequestMapping(value = "/checkData", method = RequestMethod.GET )
    @ResponseBody
    public void checkData() {
        try {
            connection = DataSource.getConnection();
            // 编写Sql
            String sql = "INSERT INTO CHECK_DATA (CHECK_ID,DATA_TIME,FACTOR_CODE,FLAG,MN,CHECK_DATA,STANDARD_VALUE) "
                    + "VALUES (?,TO_DATE(?,'yyyy-MM-dd HH24:mi:ss'),?,?,?,?,?) ";
            pstmt = connection.prepareStatement(sql);
            for (int i = 1; i <= 60; i++) {
                int x = 0;
                String stationCode = "W" + i;
                for (int j = 1; j <= 74; j++) {
                    String time = "2020-01-18 15:00:00";
                    Date date = DateUtil.stringToDate(time, DateUtil.DATE_FULL_STR);
                    String hour = DateUtil.addDate(date, j, DateUtil.DATE_FULL_STR); 
                    for (String string : checkCodeListOne) {
                        x++;
                        String value = "";
                        String standardValue = "";
                        if ("w01019".equals(string)) { // 5-10
                            value = String.valueOf(new BigDecimal( 5 + (Math.random() * 15))
                                    .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                            standardValue = "8";
                        } else if ("w21003".equals(string)) { // 0.7-0.9
                            value = String.valueOf(new BigDecimal(0.5 + (Math.random() * 1))
                                    .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                            standardValue = "0";
                        } else if ("w21011".equals(string)) { // 0.001-0.003
                            value = String.valueOf(new BigDecimal(0.1 + (Math.random() * 0.3))
                                    .setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue());
                            standardValue = "0.2";
                        } else if ("w21001".equals(string)) { // 0.01-0.1
                            value = String.valueOf(new BigDecimal(1 + (Math.random() * 2))
                                    .setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue());
                            standardValue = "4";
                        } else if ("w01001".equals(string)) {
                            value = String.valueOf(new BigDecimal(7 + (Math.random() * 1))
                                    .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                        } else if ("w01010".equals(string)) {
                            value = String.valueOf(new BigDecimal(20 + (Math.random() * 5))
                                    .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                        } else if ("w01009".equals(string)) {
                            value = String.valueOf(new BigDecimal(5 + (Math.random() * 2))
                                    .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                        } else if ("w01014".equals(string)) {
                            value = String.valueOf(new BigDecimal(400 + (Math.random() * 20))
                                    .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                        } else if ("w01003".equals(string)) {
                            value = String.valueOf(new BigDecimal(20 + (Math.random() * 15))
                                    .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                        }
                        String uuid = UUIDGenerator.getUUID();
                        // 判断是否存在
                        pstmt.setString(1, uuid);
                        pstmt.setString(2, hour);
                        pstmt.setString(3, string);
                        pstmt.setString(4, "N");
                        pstmt.setString(5, stationCode);
                        pstmt.setString(6, value);
                        pstmt.setString(7, standardValue);
                        pstmt.addBatch();
                        x++;
                        if (x % 20 == 0) {
                            pstmt.executeBatch();
                        }
                    }
                    pstmt.executeBatch();
                }
                System.out.println(stationCode + "站点插入" + x + "条数据！");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                if (connection != null) {
                    connection.close();
                }
                if (pstmt != null) {
                    pstmt.close();
                }
            } catch (SQLException e) {
                    e.printStackTrace();
            }
        }
    }
}
